package com.godchicken.praise_each_other.cim.server.controller;

import com.aliyuncs.auth.sts.AssumeRoleResponse;
import com.godchicken.praise_each_other.cim.server.constant.MsgConStant;
import com.godchicken.praise_each_other.cim.server.constant.StatusConstant;
import com.godchicken.praise_each_other.cim.server.entity.Result;
import com.godchicken.praise_each_other.cim.server.kit.Md5Kit;
import com.godchicken.praise_each_other.cim.server.kit.OssKit;
import com.godchicken.praise_each_other.cim.server.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * com.godchicken.praise_each_other.cim.server.controller
 * 2020/11/19
 *
 * @author: godchicken
 */
@RestController
@RequestMapping("cim/server/oss")
public class OssController {

    private final Logger log= LoggerFactory.getLogger(UserController.class);

    @Autowired
    private OssKit ossKit;

    @RequestMapping("/get/upload/access")
    public Result getUploadAccess(@RequestParam("id") String id, @RequestParam("type") String type){
        Logger logger = LoggerFactory.getLogger(OssController.class);
        logger.info("id:" + id + "type:" + type);

        Result result = ossKit.getUploadFormData();
        if(result == null) {
            Result errResult = new Result();
            errResult.setMsg(MsgConStant.AUTH_OSS_FAILED);
            errResult.setStatus(StatusConstant.FAILED);
            return result;
        }
        if(type.equals("faceImg")){
            result.addData("dir","user/faceImg/" + id + "/");
        }
        result.setStatus(StatusConstant.SUCCESS);
        result.setMsg(MsgConStant.AUTH_OSS_SUCCESS);

        return result;
    }


}
